package com.nbjtjc.safe.api.danger;

import com.nbjtjc.common.validator.ValidatorUtils;
import com.nbjtjc.common.validator.group.UpdateGroup;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.model.danger.DangerInspectListPublic;
import com.nbjtjc.safe.model.danger.DangerInspectPublic;
import com.nbjtjc.safe.model.danger.DangerSafePlan;
import com.nbjtjc.safe.service.danger.DangerInspectListPublicService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * @auther guqianbin
 * @date 2018/4/12 13:20
 * 发布的隐患检查项
 **/
@RestController
@RequestMapping("/danger/inspectListPublic")
@CrossOrigin("*")
public class DangerInspectListPublicController {
    @Autowired
    private DangerInspectListPublicService dangerInspectListPublicService;

    @SysLog("添加发布检查表中的一条记录")
    @RequestMapping(value = "/add", method = {RequestMethod.POST})
    public Result add(@RequestBody DangerInspectListPublic dangerInspectListPublic) {
        ValidatorUtils.validateEntity(dangerInspectListPublic);
        Result result = dangerInspectListPublicService.add(dangerInspectListPublic);
        return result;
    }

    @SysLog("删除检查表中的一条记录")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public Result delete(@RequestBody DangerInspectListPublic dangerInspectListPublic) {
        ValidatorUtils.validateEntity(dangerInspectListPublic, UpdateGroup.class);
        Result result = dangerInspectListPublicService.delete(dangerInspectListPublic);
        return result;
    }

    @SysLog("更新检查表中的一条记录")
    @RequestMapping(value = "/update", method = {RequestMethod.POST})
    public Result update(@RequestBody DangerInspectListPublic dangerInspectListPublic) {
        ValidatorUtils.validateEntity(dangerInspectListPublic, UpdateGroup.class);
        Result result = dangerInspectListPublicService.update(dangerInspectListPublic);
        return result;
    }

    @SysLog("更新检查表中的superviseUserId")
    @RequestMapping(value = "/updateList", method = {RequestMethod.POST})
    public Result updateList(@RequestParam("dangerInspectList") List<DangerInspectListPublic> dangerInspectListPublics) {
        Result result = dangerInspectListPublicService.updateList(dangerInspectListPublics);
        return result;
    }
    @PostMapping("/updateListAndTaskRecord")
    public Result updateListAndTaskRecord(@RequestBody DangerInspectPublic dangerInspectPublic){
        Result result = dangerInspectListPublicService.updateListAndTaskRecord(dangerInspectPublic);
        return result;
    }
    @RequestMapping(value = "/find", method = {RequestMethod.POST})
    public Result find(@RequestBody DangerInspectListPublic dangerInspectListPublic) {
        Result result = new Result();
        result.setData(dangerInspectListPublicService.find(dangerInspectListPublic));
        return result;
    }
}
